import './BasicProjectInformation.scss'

import { useState } from 'react'
import { useMount, useRequest, useSetState } from 'ahooks'
import { Input, Select, Button } from 'antd'

import { OpenExcel } from '../../../Modal/ModalList/AnnexList'
import { Http } from '../../../Api'

export const BasicProjectInformation = () => {
    let search = {
        ParentOrganizationUuid: '',
        OrganizationName: '',
        AccountsDueDate: '',
        IsNewProject: 2,
    }

    const [Search, setSearch] = useSetState(search)

    const { runAsync } = useRequest(Http, {
        manual: true,
        onSuccess: res => setParent(res),
    })

    const [Parent, setParent] = useState([])

    const onSearch = () => {
        setSearch(search)
    }

    const onReset = () => {
        search = {
            ParentOrganizationUuid: '',
            OrganizationName: '',
            AccountsDueDate: '',
            IsNewProject: 2,
        }
        setSearch(search)
    }

    useMount(() => {
        runAsync({ url: 'getOrganizationManagedorganizations', data: { IdentityLevel: 2 } })
    })

    return (
        <div className="BasicProjectInformation">
            <div className="search">
                <div className="label">
                    <div>公司名称 : </div>
                    <Select options={Parent} onChange={e => (search.ParentOrganizationUuid = e)} />
                </div>
                <div className="label">
                    <div>项目名称 : {search.OrganizationName} </div>
                    <Input onChange={e => (search.OrganizationName = e.target.value)} />
                </div>
                <div className="label">
                    <div>应收款项形成时间 : </div>
                    <Input onChange={e => (search.AccountsDueDate = e.target.value)} />
                </div>
                <div className="label">
                    <div>是否新项目 : </div>
                    <Select
                        defaultValue={2}
                        options={[
                            { label: '全部', value: 2 },
                            { label: '是', value: 1 },
                            { label: '否', value: 0 },
                        ]}
                        onChange={e => (search.IsNewProject = e)}
                    />
                </div>
                <div className="submit">
                    <Button type="primary" onClick={onSearch}>
                        搜索
                    </Button>
                    <Button onClick={onReset}>重置</Button>
                </div>
            </div>
            <div className="excel">
                <OpenExcel
                    key={new Date().getTime()}
                    data={{
                        data: {
                            save: true,
                            submit: true,
                            url: 'getFinanceGetBasicProjectInformation',
                            pos: 'posFinanceSaveBasicProjectInformation',
                            ...Search,
                        },
                    }}
                />
            </div>
        </div>
    )
}
